package com.adminpanel.action;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;



import com.adminpanel.modelbean.UserBean;
import com.adminpanel.modelbean.VoteBean;
import com.adminpanel.service.VoteServices;


@RequestMapping("/myinfo")
@Controller
@SessionAttributes("loginuser")
public class VoteController {
	
	
	@Resource(name = "voteServices")
	private VoteServices voteServices;
	
	@RequestMapping("myvotes")
	public String VoteIndex(@ModelAttribute("loginuser") UserBean userBean,Model model) {
		model.addAttribute("votes", voteServices.getVoteByUserId(userBean.getId()));
		return "myvote";
	}
	
	@RequestMapping(value="addvote" ,method = RequestMethod.POST)
	public String addNewVote(@ModelAttribute("loginuser") UserBean userBean,VoteBean votebean,HttpServletRequest request,ModelMap map){
		votebean.setUser_id(userBean.getId());
		votebean.setVote_title(request.getParameter("votetype"));
		voteServices.addVoteTask(votebean);
		return "redirect:myvotes";
		
		
	}
	
	
}
